﻿using Api.Common;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace AppManager.Background
{
    /// <summary>
    /// 用户是否是管理员
    /// </summary>
    public class IsAdminAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!Th.User.IsAdmin)
            {
                if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["isajax"])) //表示为ajax请求
                {
                    AjaxMsgHelper.Response(true, "你没有权限", null, "", false);
                }
                else
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary()
                        {
                            { "area",""},
                            {"controller","Account"},
                            {"action","Login" },
                        });
                }
            }
            base.OnActionExecuting(filterContext);
        }
    }
}